package com.wqr.mobile.android.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.KeyEvent;

/**
 * activity templete
 * 
 * @author wenqiurong
 * 
 */
public abstract class AbsFragmentActivity extends FragmentActivity {
	public static String TAG;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		TAG = this.getClass().getSimpleName();
		setUp();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Intent exitIntent = new Intent();// 创建Intent对象
		exitIntent.setAction("app.download.cmd.receiver");
		exitIntent.putExtra("cmd", 7); // 退出下载线程指令
		sendBroadcast(exitIntent);// 发送广播
		destory();
		Log.i(TAG, "templete onDestroy");
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			finish();
			return false;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}

	@Override
	public void onLowMemory() {
		System.gc();
		super.onLowMemory();
	}

	/**
	 * FragmentActivity Initializa
	 */
	protected abstract void setUp();

	/**
	 * clear object
	 */
	protected abstract void destory();

}
